//
//  Empty.m
//  九宫格
//
//  Created by 互联网 on 16/7/14.
//  Copyright © 2016年 aa. All rights reserved.
//

#import "Empty.h"
#import "LXAppInfo.h"

@implementation Empty


+(Empty *)appInfoViews{
    //1.从xib中加载view
    NSBundle *bundle=[NSBundle mainBundle];
    //使用自定义View加载Xib
    Empty *subview=[[bundle loadNibNamed:@"Empty" owner:nil options:nil] lastObject];
    
    return subview;
}
//重写APPInfo属性的setter方法为子控件赋值
-(void)setAppInfo:(LXAppInfo *)appInfo
{
    _appInfo=appInfo;
    self.imageView.image=[UIImage imageNamed:appInfo.icon];
    self.nameView.text=appInfo.name;
    self.nameView.font=[UIFont systemFontOfSize:12];
}

- (IBAction)downViewClick:(UIButton *)sender {
    sender.enabled=NO;
    self.superview.userInteractionEnabled=NO;
    //利用label显示下载状态
    UILabel *tipView=[[UILabel alloc]init];
    //将view添加到父控件中
    [self.superview addSubview:tipView];
    
    //frame
    CGFloat tipW=200;
    CGFloat tipH=30;
    CGFloat tipX=(self.superview.frame.size.width-tipW)/2;
    CGFloat tipY=(self.superview.frame.size.height-tipH)/2;
    
    tipView.frame=CGRectMake(tipX, tipY, tipW, tipH);
    //设置文字
    tipView.text=[NSString stringWithFormat:@"正在下载：%@",self.appInfo.name];
    //文字位置
    tipView.textAlignment=NSTextAlignmentCenter;
    //背景
    tipView.backgroundColor=[UIColor grayColor];
    tipView.alpha=0;
    //设置圆角
    tipView.layer.masksToBounds=YES;
    tipView.layer.cornerRadius=5;
    //动画
  [UIView animateWithDuration:1.0 animations:^{
      //透明度
      tipView.alpha=0.9;
      
  }completion:^(BOOL finished) {
      
      [UIView animateWithDuration:1.0 delay:3.0 options:UIViewAnimationOptionCurveLinear animations:^{
          tipView.alpha=0;
      } completion:^(BOOL finished) {
          //视图和用户可交互
         self.superview.userInteractionEnabled=YES;
  
      }];
  
  }];
    
    
    
}

@end
